package com.java1412.order.controller;

import com.java1412.common.entity.Goods;
import com.java1412.order.service.GoodsService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * 商品订单信息
 *
 * @author java1412
 * @since 2024-04-08 10:55:11
 */
@RestController
@RequestMapping("/api/v1/goods_order")
public class OrderController {

    @Resource
    private RestTemplate restTemplate;

    @RequestMapping(value = "/getGoods")
    public Object save(int goodsId) {
        Goods goods = restTemplate.getForObject("http://localhost:6001/api/v1/goods/findByGoodsId?goodsId=" + goodsId, Goods.class);
        return goods;
    }

    // 注入goodsService
    @Resource
    private GoodsService goodsService;

    @RequestMapping(value = "/getGoodsByFeign")
    public Object getGoodsByFeign(int goodsId) {
        return goodsService.findByGoodsId(goodsId);
    }

    @GetMapping(value = "/getClusterName")
    public Object getClusterName() {
        for (int i = 0; i < 10; i++) {
            System.out.println(goodsService.findClusterName());
        }
        return "ok";
    }
}
